package com.n5x.service;

import com.n5x.model.shopping.ShoppingCart;
import com.n5x.model.shopping.ShoppingOrder;
import com.n5x.model.shopping.ShoppingOrderDetails;
import com.n5x.model.shopping.ShoppingOrderExample;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/22.
 */
public interface IShoppingService {

    // 购物车 ShoppingCart
    ShoppingOrder saveNewShoppingOrderByGoods(String userId,List<ShoppingOrderDetails> orderDetails);

    /**
     * 保存或更新购物车
     *
     * @param shoppingCart 购物车对象
     * @return 购物车ID
     */
    void saveShoppingCart(ShoppingCart shoppingCart);

    /**
     * 添加购物车
     *
     * @param userId           用户ID
     * @param shoppingCartList 购物车对象(主要包括关联商品ID及数量)
     */
    void saveShoppingCart(String userId, List<ShoppingCart> shoppingCartList);

    /**
     * 删除购物车
     *
     * @param id 购物车ID
     * @return 更新数据库记录数
     */
    int deleteShoppingCart(String id);

    /**
     * 查找购物车
     *
     * @param id 购物车ID
     * @return 购物车对象
     */
    ShoppingCart findShoppingCart(String id);

    /**
     * 根据用户查找购物车
     *
     * @param userId 用户ID
     * @return 购物车列表
     */
    List<ShoppingCart> findShoppingCartByUser(String userId);

    /**
     * 根据用户及商品查找对应购物车
     *
     * @param userId  用户ID
     * @param goodsId 商品ID
     * @return 购物车对象, 没有为null
     */
    ShoppingCart findShoppingCart(String userId, String goodsId);

    // 订单信息 ShoppingOrder

    /**
     * 保存订单信息及用户优惠信息
     *
     * @param shoppingOrder   订单
     * @param userDiscountIds 用户优惠券ID
     * @return 订单信息
     */
    ShoppingOrder saveShoppingOrder(ShoppingOrder shoppingOrder, String[] userDiscountIds);

    /**
     * 订单支付
     *
     * @param shoppingOrder
     * @param userId
     * @return
     */
    Map<String,Object> saveShoppingOrderByPay(ShoppingOrder shoppingOrder,String userId) throws Exception;

    /**
     * 根据订单ID查找订单
     *
     * @param orderId 订单ID
     * @return 订单对象
     */
    ShoppingOrder findShoppingOrder(String orderId);

    /**
     * 查询订单列表
     *
     * @param criteria 查询条件
     * @return 订单列表
     */
    List<ShoppingOrder> findShoppingOrderList(ShoppingOrderExample.Criteria criteria);

    //订单明细 ShoppingOrderDetails

    /**
     * 查询订单明细
     *
     * @param shoppingOrderId 订单ID
     * @return 订单明细列表
     */
    List<ShoppingOrderDetails> findShoppingOrderDetails(String shoppingOrderId);

    /**
     * 查询订单包用户
     *
     * @param map 查询条件
     * @return 订单列表
     */
    List<ShoppingOrder> selectUserShopingOrder(Map<String,String> map);

    int countUserShopingOrder(Map map);
}
